package com.yeheng;

/**
 * @Classname SaleTicket
 * @Description :
 * @Date 2021/2/27 11:35
 * @Created by Yeheng
 */
class Ticket implements Runnable{
    private int count = 100;
    @Override
    public void run() {
        while (count > 0){
            synchronized (this){
                if (count > 0){
                    System.out.println(Thread.currentThread().getName()+"正在卖第"+count --+"张车票");
                }
            }
        }
    }
}
public class SaleTicket {
    public static void main(String[] args) {
        Ticket ticket = new Ticket();
        Thread thread = new Thread(ticket, "窗口一");
        Thread thread2 = new Thread(ticket, "窗口二");
        Thread thread3 = new Thread(ticket, "窗口三");
        Thread thread4 = new Thread(ticket, "窗口四");
        thread.start();
        thread2.start();
        thread3.start();
        thread4.start();
    }
}
